<template>
  <div class="sidebar-container">
    <!-- Logo区域 -->
    <div class="logo" :class="{ 'is-collapsed': isCollapsed }">
      <img src="/vite.svg" alt="Logo" class="logo-img" />
      <span class="logo-text" v-show="!isCollapsed">管理系统</span>
    </div>

    <!-- 导航菜单 -->
    <el-menu
      :default-active="activeMenu"
      class="sidebar-menu"
      background-color="#304156"
      text-color="#bfcbd9"
      active-text-color="#409eff"
      :collapse="isCollapsed"
      router
    >
      <!-- 首页 -->
      <el-menu-item index="/home">
        <el-icon><House /></el-icon>
        <template #title>
          <span>首页</span>
        </template>
      </el-menu-item>

      <!-- 用户管理 -->
      <el-sub-menu index="/user">
        <template #title>
          <el-icon><User /></el-icon>
          <span>用户管理</span>
        </template>
        <el-menu-item index="/user/userList">
          <el-icon><Document /></el-icon>
          <template #title>
            <span>用户列表</span>
          </template>
        </el-menu-item>
        <el-menu-item index="/user/adminList">
          <el-icon><Document /></el-icon>
          <template #title>
            <span>管理员列表</span>
          </template>
        </el-menu-item>
      </el-sub-menu>
    </el-menu>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { House, User, Document } from '@element-plus/icons-vue'

// 定义props
const props = defineProps({
  isCollapsed: {
    type: Boolean,
    default: false
  }
})

const route = useRoute()

// 当前激活的菜单
const activeMenu = computed(() => {
  return route.path
})
</script>

<style lang="scss" scoped>
.sidebar-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #2b2f3a;
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  border-bottom: 1px solid #434a50;
  transition: all 0.3s ease;

  .logo-img {
    width: 32px;
    height: 32px;
    margin-right: 8px;
    transition: margin-right 0.3s ease;
  }

  .logo-text {
    white-space: nowrap;
    transition: opacity 0.3s ease;
  }

  &.is-collapsed {
    .logo-img {
      margin-right: 0;
    }
  }
}

.sidebar-menu {
  flex: 1;
  border: none;
}
</style>
